#include "../config.h"

#include <gtkmm.h>
#include <glibmm/i18n.h>

#include "paths.h"
#include "log.h"
#include "application.h"
#include "options.h"
#include "format.h"
#include "notify.h"
#include "misc.h"

int main(int argc, char *argv[]) {
  setlocale(LC_ALL, "");

  bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR);
  bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
  textdomain(GETTEXT_PACKAGE);

  Glib::thread_init();

#if (REGEX_MODULE == REGEX_MODULE_ONIGURUMA)
  onig_init();
#endif

  gpyp::OptionContext *opts = new gpyp::OptionContext();
  Gtk::Main *kit = new Gtk::Main(argc, argv, *opts);

  gpyp::log::init(*opts);
  gpyp::log::log << PACKAGE_STRING" starting..." << gpyp::log::endl;

  gpyp::IconManager::init(*opts);
  gpyp::Notify::init();

  gpyp::Application *app = new gpyp::Application(*opts);
  int res = app->main(*kit);
  delete app;
  delete kit;
  delete opts;

  gpyp::Notify::uninit();
  gpyp::log::log << "...shutdown" << gpyp::log::endl;
  gpyp::log::uninit();

#if (REGEX_MODULE == REGEX_MODULE_ONIGURUMA)
  onig_end();
#endif
  return res;
}
